<!--获取时间-->
<template>
    <div class="get-time">
       <el-form>
           <el-form-item label="选取字段">
                <el-select size="mini" v-model="value1" @change="selectHandle" clearable>
                    <el-option
                        v-for="item in value1List"
                        :key="item.value"
                        :value="item.value"
                        :label="item.label"></el-option>
                </el-select>
               <span>{{message}}</span>
           </el-form-item>
           <el-form-item label="获取时间" >
                <el-select size="mini"  v-model="value2" filterable @change="selectHandle">
                    <el-option
                        v-for="item in value2List"
                        :key="item.value"
                        :value="item.value"
                        :label="item.label"></el-option>
                </el-select>
           </el-form-item>
       </el-form>
    </div>
</template>

<script>
    export default {
        name: 'GetTime',
        data () {
            return {
                value1: '',
                value1List: [],
                value2: '',
                value2List: [
                    {
                        value: '1',
                        label: '年份'
                    }, {
                        value: '2',
                        label: '季度'
                    }, {
                        value: '3',
                        label: '月份'
                    }, {
                        value: '4',
                        label: '月日'
                    }, {
                        value: '5',
                        label: '星期'
                    }, {
                        value: '6',
                        label: '日'
                    }, {
                        value: '7',
                        label: '周数'
                    }, {
                        value: '8',
                        label: '时'
                    }, {
                        value: '9',
                        label: '分'
                    }, {
                        value: '10',
                        label: '秒'
                    }, {
                        value: '11',
                        label: '年季度'
                    }, {
                        value: '12',
                        label: '年月'
                    }, {
                        value: '13',
                        label: '年周数'
                    }, {
                        value: '14',
                        label: '年月日'
                    }, {
                        value: '15',
                        label: '年月日时'
                    }, {
                        value: '16',
                        label: '年月日时分'
                    }, {
                        value: '17',
                        label: '年月日时分秒'
                    }
                ],
                columnInfo: [],
                tempList: [],
                pageMode: 'ADD',
                message: ''
            }
        },
        props: {
            menuId: {
                type: String
            }
        },
        methods: {
            // 获取对应标签值
            getLabel (dataList, val) {
                let label = ''
                dataList.forEach(item => {
                    if (item.value === val) {
                        label = item.label
                    }
                })
                return label
            },
            saveColumnInfo (val) {
                this.handleTreeValue(val)
                this.value1 = this.value1List.length > 0 ? this.value1List[0].value : ''
                this.value2 = this.value2List[0].value
                let param = {
                    value1: this.value1,
                    value2: this.value2,
                    pageMode: sessionStorage.getItem('pageMode')
                }
                this.$emit('getTimeValue', param)
            },
            // 编辑接收值
            editData (dataValue) {
                this.value1 = dataValue.value1
                this.value2 = dataValue.value2
                let param = {
                    value1: this.value1,
                    value2: this.value2,
                    pageMode: sessionStorage.getItem('pageMode')
                }
                this.$emit('getTimeValue', param)
            },
            // 接收树的值进行处理
            handleTreeValue (treeValue) {
                this.columnInfo = treeValue
                this.tempList = this.columnInfo[0].children
                if (this.tempList.length > 0) {
                    this.tempList.forEach(item => {
                        this.value1List.push({
                            value: item.enName,
                            label: item.name
                        })
                    })
                }
            },
            selectHandle () {
                this.message = ''
                let param = {
                    value1: this.value1,
                    value2: this.value2,
                    pageMode: sessionStorage.getItem('pageMode')
                }
                this.$emit('getTimeValue', param)
            },
            changeMsg (val) {
                this.message = val
            }
        }
    }
</script>

<style lang="stylus" rel="stylesheet/stylus">
    .get-time
        .el-form
            margin-top 10px
            .el-form-item
                margin-bottom 0px
</style>
